package com.ruoyi.project.drug.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.drug.domain.DrugFactory;
import com.ruoyi.project.drug.service.IDrugFactorySercice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/drug/factory")
public class DrugFactoryController extends BaseController {
    @Autowired
    private IDrugFactorySercice iDrugFactorySercice;
    @PreAuthorize("@ss.hasPermi('drug:factory:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugFactory DrugFactory)
    {
        startPage();
        List<com.ruoyi.project.drug.domain.DrugFactory> list = iDrugFactorySercice.selectDrugFactoryList(DrugFactory);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('drug:factory:add')")
    @Log(title = "厂家维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody DrugFactory drugFactory)
    {
        drugFactory.setCreateBy(SecurityUtils.getUsername());
         return toAjax(iDrugFactorySercice.insertDrugFactory(drugFactory));
    }

    @PreAuthorize("@ss.hasPermi('drug:factory:remove')")
    @Log(title = "厂家维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{factoryIds}")
    public AjaxResult remove(@PathVariable Long[] factoryIds)
    {
        return toAjax(iDrugFactorySercice.deleteDrugFactory(factoryIds));
    }


    @PreAuthorize("@ss.hasPermi('drug:factory:edit')")
    @Log(title = "厂家维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody DrugFactory drugFactory)
    {
        drugFactory.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iDrugFactorySercice.updateDrugFactory(drugFactory));
    }

    @PreAuthorize("@ss.hasPermi('drug:factory:query')")
    @GetMapping(value = "/{factoryId}")
    public AjaxResult getInfo(@PathVariable Long factoryId)
    {
        return AjaxResult.success(iDrugFactorySercice.selectDrugFactoryById(factoryId));
    }
}
